define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function(params) {
        controller.vm = new Vue({
            router: router,
            data: function data() {
                return {
                    user_info: {
                        community:{},
                        tenement_type:[]
                    },
                  
                    page: 1,
                    lastPage:0,
                    mounted: 0,
                    room_info: {},
                    showNoData:0,
                    bills_list:[],
                    nodata:0,
                      shop_id:0,
                    shop_info:{},
                    bill_amount:"0.00"
                };
            },
            el: "#pageBillsRecords",
            created: function created() {
                 this.shop_id = this.$route.params.shop_id;
                // this.getShopInfo();
                
                this.getBillList();
            },

            mounted: function mounted() {
                    if (this.mounted == 1) {
                        return;
                    }
                     var that = this ;
                    app.pager("#pageBillsRecords",function(){
                       that.getBillList();
                    });
                    this.mounted = 1;
                    
                     
            },
            methods: {
                   getShopInfo:function(){
                    var that = this;
                    app.get("/mall/shop/find",{
                        
                    },function(res){
                         if(res.code==200){
                             that.shop_info = res.data;
                         }
                        
                    });
                },
                getRoomInfo:function(){
                   var out_room_id = this.$route.params.out_room_id;
                   var that = this;
                    app.get("/api/community_rooms/find",{
                      out_room_id:out_room_id
                     },function(res){
                         if(res.code!=200){
                             app.alert(res.msg);
                         }
                         that.room_info = res.data;
                        
                    });

                },
                getBillList:function(){
                   var out_room_id = this.$route.params.out_room_id;
                   var that = this;
                   var page = this.page;
                   if(that.lastPage==1 || this.loading==1){
                    return ;
                   }
                   this.loading = 1;
                    app.get("/mall/shop_bills/get",{
                      // shop_id:this.shop_id,
                      page:page,
                      limit: 20,
                      status:1
                     },function(res){
                         if(res.code!=200){
                             app.alert(res.msg);
                         }
                         // that.bills_list = res.data.list;
                        if (res.data.list.length === 0) {
                          that.lastPage=1;
                        }

                      page++;
                      if (res.data.list.length>0) {
                        that.setData({ page: page, loading: 0, 'bills_list': that.bills_list.concat(res.data.list) });
                      }
                       if (that.bills_list.length === 0) {
                          that.nodata=1;
                       }
                      
                        
                    });
                },
                countPrice:function(){
                  var bill_amount=0;
                  $("[name='checkbox1']:checked").each(function(i,checkbox){
                    bill_amount+=Number($(checkbox).attr("data-bill_entry_amount"));
                  });
                  this.bill_amount = bill_amount;

                },
                selectAll:function(){
                  if( $("[name='checkbox2']").prop("checked")){
                     $("[name='checkbox1']").prop("checked",true);
                  }else{
                     $("[name='checkbox1']").prop("checked",false);     
                  }
                  
                   this.countPrice();
                },
                postOrder:function(){
                  var bill_entry_ids=[];
                  $("[name='checkbox1']:checked").each(function(i,checkbox){
                    bill_entry_ids.push($(checkbox).attr("data-bill_entry_id"));
                  });
                  if(bill_entry_ids.length===0){
                    return ;
                  }
                  app.post("/api/pay/community_bills_order",{
                     bill_entry_id:bill_entry_ids.join(","),
                  },function(res){
                      if(res.code!=200){
                        app.alert(res.msg);
                        return;
                      }
                      app.pay(res.data.order_sn);
                  });
                  // console.log(bill_entry_ids);
                },
             
                setData:function(data){
                     for(var i in data){
                        this[i]=data[i];
                     }
                  },
                   
              }
        }).$mount("#app");
    };
    controller.pageShow = function() {};
    module.exports = controller;
});
